<template>
  <Dialog v-model="dialogVisible" title="描述">
    <el-input
      v-model="inputDes"
      placeholder="请输入描述"
      type="textarea"
      maxlength="500"
      show-word-limit
    />
    <template #footer>
      <el-button :disabled="formLoading" type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="dialogVisible = false">取 消</el-button>
    </template>
  </Dialog>
</template>

<script setup lang="ts">
const dialogVisible = ref(false)
const inputDes = ref()
const formLoading = ref(false) // 表单的加载中:1）修改时的数据加载；2）提交的按钮禁用
const message = useMessage() // 消息弹窗

/** 打开弹窗 */
const open = async (des) => {
  dialogVisible.value = true
  resetForm()
  inputDes.value = des
}
const resetForm = () => {
  inputDes.value = ''
}
defineExpose({ open }) // 提供 open 方法，用于打开弹窗

const emit = defineEmits(['success'])

/** 提交表单 */
const submitForm = async () => {
  dialogVisible.value = false
  // 发送操作成功的事件
  emit('success', inputDes.value)
}
</script>

<style scoped></style>
